[HVM][HAP] Fix up some memory allocation bugs
authorTim Deegan <Tim.Deegan@xensource.com>
Wed, 28 Mar 2007 08:40:42 +0000 (08:40 +0000)
committerTim Deegan <Tim.Deegan@xensource.com>
Wed, 28 Mar 2007 08:40:42 +0000 (08:40 +0000)
The attached patch initializes count_info of newly allocated hap page
with 0, and removes unnecessary page deallcation when destroying monitor
table. Without this patch, destroying hap domain will fail.

Signed-off-by: Wei Huang (wei.huang2@amd.com)
xen/arch/x86/mm/hap/hap.c

index 57a2ee4fd4912452d2d93048aa13d5e3209c458c..f879c083c0b911684035ec64368673bb2a0547b7 100644 (file)
@@ -135,6 +135,7 @@ void hap_free_p2m_page(struct domain *d, struct page_info *pg)
         HAP_ERROR("Odd p2m page count c=%#x t=%"PRtype_info"\n",
                   pg->count_info, pg->u.inuse.type_info);
     }
+    pg->count_info = 0;
     /* Free should not decrement domain's total allocation, since 
      * these pages were allocated without an owner. */
     page_set_owner(pg, NULL); 
@@ -182,6 +183,7 @@ hap_set_allocation(struct domain *d, unsigned int pages, int *preempted)
             list_del(&sp->list);
             d->arch.paging.hap.free_pages -= 1;
             d->arch.paging.hap.total_pages -= 1;
+            sp->count_info = 0;
             free_domheap_pages(sp, 0);
         }
         
@@ -367,17 +369,7 @@ void hap_destroy_monitor_table(struct vcpu* v, mfn_t mmfn)
 {
     struct domain *d = v->domain;
 
-#if CONFIG_PAGING_LEVELS == 4
-    /* Need to destroy the l3 monitor page in slot 0 too */
-    {
-        mfn_t m3mfn;
-        l4_pgentry_t *l4e = hap_map_domain_page(mmfn);
-        ASSERT(l4e_get_flags(l4e[0]) & _PAGE_PRESENT);
-        m3mfn = _mfn(l4e_get_pfn(l4e[0]));
-        hap_free(d, m3mfn);
-        hap_unmap_domain_page(l4e);
-    }
-#elif CONFIG_PAGING_LEVELS == 3
+#if CONFIG_PAGING_LEVELS == 3
     /* Need to destroy the l2 monitor page in slot 4 too */
     {
         l3_pgentry_t *l3e = hap_map_domain_page(mmfn);
@@ -632,10 +624,6 @@ void hap_update_paging_modes(struct vcpu *v)
 
     v->arch.paging.translate_enabled = !!hvm_paging_enabled(v);    
 
-    /* use p2m map */
-    v->arch.guest_table =
-        pagetable_from_pfn(pagetable_get_pfn(d->arch.phys_table));
-
     if ( pagetable_is_null(v->arch.monitor_table) ) {
         mfn_t mmfn = hap_make_monitor_table(v);
         v->arch.monitor_table = pagetable_from_mfn(mmfn);